﻿/*  For more information on this example visit the article to this code on my blog at 
 *  http://www.ticklishtechs.net/2008/04/12/to-restrict-dynamically-the-usage-of-domain-properties-in-dsl-models/ */
 
using BenjaminSchroeter.Dsl.UserRestrictions;

namespace BenjaminSchroeter.RestrictPropertiesExample
{
    [RestrictedProperty((int)RestrictionModes.Simple, "Pa", Restriction.Hidden)]
    [RestrictedProperty((int)RestrictionModes.Simple, "Pb", Restriction.ReadOnly)]
    [RestrictedProperty((int)RestrictionModes.Simple, "Pc", Restriction.ReadOnly)]

    [RestrictedProperty((int)RestrictionModes.Advanced, "Pa", Restriction.Full)]
    [RestrictedProperty((int)RestrictionModes.Advanced, "Pb", Restriction.Full)]
    [RestrictedProperty((int)RestrictionModes.Advanced, "Pc", Restriction.ReadOnly)]

    [CustomRestrictedProperty("CustomProperty")]
    partial class ExampleElement : ISupportsUserRestrictions
    {
        public Restriction GetRestriction(string property)
        {
            if (property == "CustomProperty")
            {
                if (!this.CustomPropertyVisible)
                    return Restriction.Hidden;

                if (this.CustumPropertyReadOnly)
                    return Restriction.ReadOnly;

                return Restriction.Full;
            }

            return Restriction.Full;
        }
    }
}